var express = require('express');
var router = express.Router();

//查询
router.get('/student/:stuid', function(req, res, next) {
    console.log("4654658465");
    let {stuid}= req.params;
    res.json({stuid:parseInt(stuid),name:"张三"})
});

//新增
router.post("/student/:stuid",function (req,res) {
    let {stuid}= req.params;
    res.json({code:0,msg:"添加成功",stuid:parseInt(stuid)})

})

//删除
router.delete("/student/:stuid",function (req,res) {
    let {stuid}= req.params;
    res.json({code:0,msg:"删除成功",stuid:parseInt(stuid)})

})

//修改（实际上有两个操作，一个是查询 一个修改）
//多参数： /:oldId/:newId 路径上需要传递两个参数
router.put("/student/:oldId/:newId",(req,res)=>{
    let {oldId,newId}= req.params;
    res.json({code:0,msg:"修改成功","oldId":parseInt(oldId),"newId":parseInt(newId)})
});

//根据名字查询学生信息
router.get("/getstudentbyName/:stuname",(req,res)=>{
    let {stuname} = req.params;
    res.json({code:0,msg:"查询",name:stuname})
})





module.exports = router;
